/*
 * deleteFile.java
 *
 * Created on March 26, 2007, 7:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.actions;

import javax.servlet.http.*;
import edu.byu.isys413.group1E.data.*;
import edu.byu.isys413.group1E.handlers.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/** This action responds to a request from the web interface to delete a selected file.
 *
 * @author Travis Kulbeth
 */
public class deleteFile implements edu.byu.isys413.web.Action {
    
    /** Creates a new instance of loadCatalog */
    public deleteFile() {
    }
    
    /**
     *Process method retrieves the GUID of the file to be deleted from the database first.  With that guid, it
     *reads the file's metadata from BackupData and creates a new RecycleBin object with that data.  The file is then
     *stored in the RecycleBin table for a defined period of time until permanently deleted.
     *
     * @return String the name of the jsp to call
     * @param request contains the HttpServletRequest data
     * @param response contains the HttpServletResponse data
     * @throws java.lang.Exception to catch any errors and forward them to the ui level
     */
    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        String guid = (String)request.getParameter("guid");
        
        //read the backup to be deleted from the BackupData table
        BackupDataBO bkData = BackupDataDAO.getInstance().read(guid);
        
        //save the file to the RecycleBin
        RecycleBinHandler.getInstance().saveFileToRecycleBin(FileHandler.getInstance().readFileByGUID(guid), bkData);
        
        //delete the file from BackupData
        BackupDataDAO.getInstance().delete(guid);
        
        //reload the current storage page
        return "edu.byu.isys413.actions.loadExistingStorage.action";
    }
    
}
